package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.ArticleExample;
import com.briup.jz.bean.Platform;
import com.briup.jz.bean.PlatformExample;
import com.briup.jz.dao.PlatformMapper;
import com.briup.jz.service.PlatformService;
import com.briup.jz.utils.CustomerException;
@Service
public class PlatformServiceImpl implements PlatformService{
	@Autowired
	private PlatformMapper platformMapper;
	@Override
	public void saveOrUpdate(Platform platform) throws CustomerException {
		// TODO Auto-generated method stub

		if(platform.getId()!=null) {
			platformMapper.updateByPrimaryKey(platform);
		}else {
			// 判断是否有同名，如果有抛出异常
//			PlatformExample example = new PlatformExample();
//			example.createCriteria().andIdEqualTo(Platform.getId());
//			List<Platform> list = platformMapper.selectByExample(example);
//			if(list.size()>0) {
//				throw new CustomerException("同名已存在");
			platformMapper.insert(platform);
			}
	}
	@Override
	public List<Platform> query(Long id,String bankCard) {
		// 模板
		PlatformExample example=new PlatformExample();
		/*条件*/
		PlatformExample.Criteria criteria = example.createCriteria();
		if(id!=null) {
			criteria.andIdEqualTo((long)id);
		}
		if(bankCard!=null) {
			criteria.andBankCardLike("%"+bankCard+"%");
		}
		List<Platform> list = platformMapper.selectByExample(example);
//		for(Platform a:list) {
//			System.out.println(a);
//		}
//		System.out.println("zzzzzz");
		return list;
	}
	@Override
	public void deleteById(long id) throws CustomerException {
		// TODO Auto-generated method stub
		Platform address=platformMapper.selectByPrimaryKey(id);
		if(address==null) {
			throw new CustomerException("要删除不存在");
		}
		platformMapper.deleteByPrimaryKey(id);
	}
}
